#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int
main(void)
{
	int fd = open("/dev/tty", O_RDONLY | O_NONBLOCK);
	if(fd < 0){
		perror("open terminal faild");
		exit(0);
	}
	printf("open fd = %d\n",fd);

	char buffer[1024];
	int n = 0;
	while(1)
	{
		n = read(fd, buffer, 10);
		if(n < 0 && errno == EAGAIN) 
		{
			printf("please write on terminal:\n");
			sleep(10);
			continue;
		}
		
		else if(n < 0){
			perror("read faild\n");
			exit(0);
		}
		else{
			write(STDOUT_FILENO, buffer, n);
			break;
		}
	}
	return 0;
}
	